package com.tianji.promotion.task;

import com.tianji.promotion.service.ICouponService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class CouponTask {

    private final ICouponService couponService;

    /**
     * 定时扫描那些还没有上架的优惠券，如果到了上架时间，就上架
     * 存入redis里面
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void openCouponTask() {
        couponService.openCouponTask();
    }

    /**
     * 定时扫描那些过了上架时间的优惠券，如果到了下架时间，就下架，从redis里面扫描
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void clearCouponTask() {
        couponService.clearCouponTask();
    }


    /**
     * 定时扫描那些过提前两天就要到期的，从redis里面扫描
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void tiXingCouponTask() {
        couponService.tiXingCouponTask();
    }


}
